<template>
	<view>
		<view class="top">
				<!-- #ifdef APP-PLUS || H5 -->
			<view class="flex_fec uni-pt-10">
				<view class="edit-button flex_fsc" @click.stop="switchStanding">
					<uni-icons type="person-filled" size="20" color="#00ab64"></uni-icons>
					<view>切换为教练</view>
				</view>
				<navigator
					class="edit-button"
					hover-class="none"
					url="/pages/my/personal-setting/personal-setting"
				>
					编辑
				</navigator>
			</view>
			<!-- #endif -->
			<view class="user" v-if="user.userId">
				<view class="left">
					<navigator hover-class="none" url="/pages/my/personal-setting/personal-setting">
						<image :src="setting.oss_pub_domain + user.avatar" class="avatar" />
					</navigator>
					<view>
						<navigator hover-class="none" url="/pages/my/personal-setting/personal-setting" class="name">
							<text class="u-line-1">{{ user.nickName }}</text>
							<image :src="`${setting.sImgUrl}/mine/man.png`" v-if="user.sex == 1"></image>
							<image :src="`${setting.sImgUrl}/mine/woman.png`" v-if="user.sex == 2"></image>
						</navigator>
						<view class="flex_sbc">
							<view class="id">ID: {{ user.userId }}</view>
							
						</view>
					</view>
				</view>
				<!-- #ifdef MP-WEIXIN -->
				<navigator
					class="edit-button"
					hover-class="none"
					url="/pages/my/personal-setting/personal-setting"
				>
					编辑
				</navigator>
				<!-- #endif -->
			</view>
			<view class="user" v-else>
				<navigator class="left" url="/pages/my/login/login">
					<image class="avatar" :src="setting.oss_pub_domain + '/app-img/icon/avatar.png'" />
					<view>注册/登录</view>
				</navigator>
			</view>

			<view class="dsc">{{ user.dsc || '这家伙很懒什么也没留下~' }}</view>
			<view class="sum">
				<navigator class="score flex_cc" hover-class="none" url="/pages/student/score/score">
					<view class="flex_sh">积分:</view>
					<view>{{ user.integral || 0 }}</view>
				</navigator>
				<view class="right rights">
					<view class="uni-mr-16">{{ hisAvg.label }}</view>
					<view v-if="user.userId" class="custom-dj">
						<view class="u-line-1 uni-ml-52">
							{{ hisAvg.remark }}
						</view>
					</view>
				</view>
			</view>
			<view class="icon">
				<view class="icon_row">
					<navigator hover-class="none" url="/pages/course/schedule/schedule">
						<image :src="`${setting.sImgUrl}/mine/icon1.png`"></image>
						<view>训练时间表</view>
					</navigator>
				</view>
				<!-- <view class="icon_row">
					<image :src="`${setting.sImgUrl}/mine/icon2.png`"></image>
					<view>技术档案</view>
				</view> -->
				<view class="icon_row">
					<navigator hover-class="none" url="/pages/student/score/score">
						<image :src="`${setting.sImgUrl}/mine/icon3.png`"></image>
						<view>赚取积分</view>
					</navigator>
				</view>
				<!-- <view class="icon_row">
					<navigator hover-class="none" url="/pages/station-message/index">
						<image :src="setting.oss_pub_domain + '/app-img/my/message.png'"></image>
						<view>通知</view>
					</navigator>
					<view v-if="noReadCount" class="no-read-number">{{ noReadCount }}</view>
				</view> -->
				<view class="icon_row">
					<navigator hover-class="none" url="/pages/my/setting/setting">
						<image :src="`${setting.sImgUrl}/mine/icon4.png`"></image>
						<view>设置</view>
					</navigator>
				</view>
			</view>
		</view>
		<view class="count">
			<view class="title">我的训练</view>
			<view class="entry">
				<navigator class="row" hover-class="none" open-type="switchTab" url="/pages/tabbar-page/tabbar-3">
					<view>专属训练</view>
					<view class="sub">{{ my_train.instructorNum }}</view>
				</navigator>
				<navigator class="row" hover-class="none" url="/pages/student/course/entry">
					<view>训练课程</view>
					<view class="sub">
						已完成{{ my_train.courseFinishNum }}节 | 未开始{{ my_train.courseStarterNum }}节
					</view>
				</navigator>
				<navigator class="row" hover-class="none" url="/pages/student/course/entry?type=2">
					<view>我的提问</view>
					<view class="sub">
						已解答{{ my_train.questionAnswerNum }} | 未解答{{ my_train.questionNotAnswerNum }}
					</view>
				</navigator>
				<navigator class="row" hover-class="none" url="/pages/student/evaluation/evaluation">
					<view>我的测评</view>
					<view class="sub">
						已测评{{ my_train.evaluationNum }}个 | 未测评{{ my_train.notEvaluationNum }}个
					</view>
				</navigator>
			</view>
		</view>
		<view class="train">
			<view class="train_time">
				<view class="part">
					<view>训练时间</view>
					<navigator class="more" hover-class="none" url="/pages/course/schedule/schedule">
						更多时间
					</navigator>
				</view>
				<view class="calendar">
					<view v-for="(v, k) in calendar" :key="k" :class="v.active ? 'active' : ''" @click="change_date(k)">
						<view class="w">{{ v.week }}</view>
						<view class="d">{{ v.day }}</view>
					</view>
				</view>
				<view v-if="course.length" class="entry">
					<view v-for="item in course" :key="item.id" class="row">
						<view class="flex_fsc">
							<view class="z-font-36 text-w">{{ item.beginTime.split(' ')[1] }}</view>
							<view v-if="item.status" class="status uni-color-main-grey uni-F5F5F5-bg">已完成</view>
							<view v-else-if="nowTimeStamp >= item.beginTimeStamp" class="status uni-red FFF0F0-bg">
								已逾期
							</view>
							<view v-else class="status uni-color-main-grey uni-F5F5F5-bg">未开始</view>
						</view>
						<view class="part2">
							<image :src="setting.oss_pub_domain + item.studentAvatar"></image>
							<view>
								<view class="name">{{ item.studentName }}</view>
								<view class="lesson">{{ item.name }}</view>
							</view>
						</view>
					</view>
				</view>
				<z-no-data v-else placeholder="暂无课程"></z-no-data>
			</view>
		</view>
	</view>
</template>

<script>
import { appointmentGiveLessonsList, appointmentGiveLessonsDetail } from '@/api/course.js';
import { getUser, myCourse_center, getTrainCourse } from '@/api/student';
export default {
	props: {
		noReadCount: Number
	},
	data() {
		return {
			a_type: 1,
			user: {},
			calendar: [],
			date: '',
			persent: 0,
			my_train: '',
			course: [],
			nowTimeStamp: Date.now(),
			scoreList: JSON.parse(JSON.stringify(this.$gc.score)).reverse()
		};
	},
	computed: {
		hisAvg() {
			return this.scoreList.filter((item) => item.code == this.userInfo.hisAvg)[0] || {};
		}
	},
	methods: {
		change_date(k) {
			for (let i in this.calendar) {
				this.calendar[i].active = false;
				if (i == k) {
					this.calendar[i].active = true;
					this.date = this.calendar[i].date;
					this.getTrainCourse();
				}
			}
		},
		change_type(type) {
			this.a_type = type;
		},
		getUserInfo() {
			getUser().then((res) => {
				this.user = res;
			});
		},
		getMyTrain() {
			myCourse_center().then((res) => {
				this.my_train = res;
			});
		},
		getDate() {
			var new_Date = new Date();
			var timesStamp = new_Date.getTime();
			var currenDay = new_Date.getDay();
			var dates = [];
			var week = ['周日', '周一', '周二', '周三', '周四', '周五', '周六'];
			for (var i = 0; i < 7; i++) {
				var time = new Date(timesStamp + 24 * 60 * 60 * 1000 * (i - ((currenDay + 7) % 7)));
				time = time.getFullYear() + '-' + (time.getMonth() + 1) + '-' + time.getDate();
				let num = time.split('-')[2];
				if (num < 10) num = '0' + num;
				if (i == 0) this.date = time;
				dates.push({ date: time, day: num, week: week[i], active: i == 0 ? true : false });
			}
			this.calendar = dates;
			console.log(this.calendar);
		},
		getTrainCourse() {
			getTrainCourse({ startDate: this.date, endDate: this.date }).then((res) => {
				res.rows.forEach((item) => {
					item.beginTimeStamp = Date.parse(item.beginTime);
				});
				this.course = res.rows;
			});
		},
		showFun() {
			this.getUserInfo();
			this.getMyTrain();
			this.getDate();
			this.getTrainCourse();
		},
		switchStanding() {
			uni.showModal({
				title: '提示',
				content: `是否要切换为教练身份`,
				success: (res) => {
					if (res.cancel) return;
					uni.setStorageSync('start-state', 1);
					uni.reLaunch({
						url: '/pages/tabbar-page/tabbar-0'
					});
				}
			});
		}
	}
};
</script>

<style lang="scss">
@import './css/mine.scss';
.no-read-number {
	position: absolute;
	right: 45rpx;
	top: -10rpx;
	width: 40rpx;
	height: 40rpx;
	text-align: center;
	line-height: 40rpx;
	color: #FFFFFF;
	background-color: #ff4a4a;
	border-radius: 120rpx;
}
</style>
